package com.hh.fudan.project_management.basic;

import java.net.URLEncoder;

public class TextUtil {
	/** Split multiple keywords with "," */
	public static String splitMultiKeywords(String input) {
		String tmp = input;
		while (tmp.indexOf("  ") >= 0) {
			tmp = tmp.replaceAll("  ", " ");
		}
		String []list=tmp.split(" ");
		String result="";
		for (int i=0;i<list.length;i++){
			result+=URLEncoder.encode(list[i]);
			result+=",";
		}
		return result.substring(0,result.length()-1);
	}
	public static String splitKeywords(String input) {
		String tmp = input;
		while (tmp.indexOf("  ") >= 0) {
			tmp = tmp.replaceAll("  ", " ");
		}
		return tmp.replaceAll(" ",",");
	}

	/** get the position of the string in the array */
	public static int getStringIndex(String curitem, String[] items) {
		for (int i = 0; i < items.length; i++) {
			if (curitem.equals(items[i]))
				return i;
		}
		return -1;
	}
}
